$(function() {
    if ($("#login_form").length > 0) {
        $("#login_form").validate({
            rules: {
                "signin[username]": {
                    required: true
                },
                "signin[password]": {
                    required: true
                }
            },
            messages: {
                "signin[username]": {
                    required: "必填项"
                },
                "signin[password]": {
                    required: "必填项"
                }
            },
            errorPlacement: function(a, b) {
                a.insertBefore(b)
            },
            errorElement: "p",
            errorClass: "form_error_item",
            submitHandler: function(a) {
                dianexia.btnInteractive($("#login_btn"));
                a.submit()
            }
        })
    }
});
$(function() {
    if ($("#register_form").length > 0) {
        $("#register_form").validate({
            rules: {
                "sf_guard_user[username]": {
                    required: true,
                    rangelength: [5, 16],
                    remote: "/api.php/json/checkUsername"
                },
                "sf_guard_user[password]": {
                    required: true,
                    rangelength: [6, 20]
                },
                "sf_guard_user[repeatPassword]": {
                    required: true,
                    equalTo: "#sf_guard_user_password"
                },
                "sf_guard_user[email]": {
                    required: true,
                    email: true,
                    remote: "/api.php/json/checkEmail"
                },
                agreement: {
                    required: true
                }
            },
            messages: {
                "sf_guard_user[username]": {
                    required: "必填项",
                    rangelength: "用户名必须在5到16位字符之间",
                    remote: "用户名已被使用"
                },
                "sf_guard_user[password]": {
                    required: "必填项",
                    rangelength: "密码长度必须在6到20位之间"
                },
                "sf_guard_user[repeatPassword]": {
                    required: "两次密码输入不一致",
                    equalTo: "两次密码输入不一致"
                },
                "sf_guard_user[email]": {
                    required: "必填项",
                    email: "请输入正确的Email地址",
                    remote: "Email地址已被使用"
                },
                agreement: {
                    required: '不同意我们的使用条款吗？来<a href="/feedback" title="反馈留言">反馈留言</a>告诉我们您的理由吧'
                }
            },
            errorPlacement: function(a, b) {
                if (b.attr("type") == "checkbox") {
                    a.insertAfter("#register_form .reg_button_wrapper")
                } else {
                    a.insertBefore(b)
                }
            },
            errorElement: "p",
            errorClass: "form_error_item",
            submitHandler: function(a) {
                dianexia.btnInteractive($("#register_btn"));
                a.submit()
            }
        })
    }
});
$(function() {
    $("#bind_btn").click(function() {
        dianexia.btnInteractive($(this))
    })
});
$(function() {
    $("#create_display").click(function(b) {
        var a = this;
        $(a).hide();
        $("#bind_display").show();
        $("#bind_field").hide();
        $("#create_field").slideDown();
        return false
    });
    $("#bind_display").click(function(b) {
        var a = this;
        $(a).hide();
        $("#create_display").show();
        $("#create_field").hide();
        $("#bind_field").slideDown();
        return false
    })
});